//
// Created by liushuai on 2021/2/25.
//

#include "findContentChildren.h"

int findContentChildren(vector<int> &g, vector<int> &s) {
    std::sort(g.begin(), g.end());
    std::sort(s.begin(), s.end());
    int min_size = g.size() < s.size() ? g.size() : s.size();
    int start1 = 0, start2 = 0, res = 0;
    while (start1 < g.size() && start2 < s.size()) {
        int current = g[start1];
        while (start2<s.size() && s[start2]<current)
            start2++;
        if(start2==s.size()){
            break;
        }
        if(start2<s.size()){
            ++res;
            ++start2;
            ++start1;
        }
    }
    return res;
}